package logic

import (
	"gorm.io/gorm"
	"project/study-go/db"
	"project/study-go/ecode"
	"project/study-go/model"
)

type UserLogic struct {}

var DefaultUser = &UserLogic{}

//GetUserInfoByUid 通过用户id获取用户信息
func (u UserLogic)GetUserInfoByUid(uid string)(*model.UserInfo,ecode.ErrorCode){
	userInfo := &model.UserInfo{}
	result := db.MasterDB.Where("uid=?", uid).First(userInfo)
	if result.Error == gorm.ErrRecordNotFound {
		return nil, ecode.ErrorCode{ecode.ErrUsernameNotRegister, 400}
	} else if result.Error != nil {
		return nil, ecode.ErrorCode{ecode.ErrInternalError, 500}
	}
	return userInfo, ecode.ErrorCode{nil, 200}
}